package j.framework.tags.form;

import j.util.StringUtils;

import javax.servlet.jsp.JspException;

/**
 * User: jason
 * Date: 2014/12/18 11:38
 */
public class TextareaTag extends BaseInputTag {

    private Integer rows;

    private Integer cols;

    private String textareaValue;

    @Override
    public String getInputType() {
        return null;
    }

    @Override
    public void writeFormTagBegin(FormTagWriter writer) throws JspException {
        writer.beginTag("textarea");
    }

    @Override
    public void writeFormTagProperties(FormTagWriter writer) throws JspException {
        super.writeFormTagProperties(writer);
        if(null!=rows && rows>0){
            writer.writeFormTagProperty("rows",rows.toString());
        }
        if(null!=cols && cols>0){
            writer.writeFormTagProperty("rows",cols.toString());
        }
    }

    @Override
    public void endBeginTag(FormTagWriter writer) throws JspException {
        writer.writeSomething(">");
        if(StringUtils.isNotEmpty(textareaValue)){
            writer.writeSomething(textareaValue);
        }else{
            Object value = getFormDataValue();
            if(value!=null){
                writer.writeSomething(value.toString());
            }
        }
        writer.closeTag("textarea");
    }

    @Override
    public void writeInputTagValue(FormTagWriter writer, Object value) throws JspException {
        if(null!=value){
            textareaValue = value.toString();
        }
    }

    @Override
    public String getCssClassName() {
        return null;
    }

    public void setRows(Integer rows) {
        this.rows = rows;
    }

    public void setCols(Integer cols) {
        this.cols = cols;
    }
}
